

var _typeof4 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _typeof3 = typeof Symbol === "function" && _typeof4(Symbol.iterator) === "symbol" ? function (obj) {
    return typeof obj === "undefined" ? "undefined" : _typeof4(obj);
} : function (obj) {
    return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof4(obj);
};

var _typeof2 = typeof Symbol === "function" && _typeof3(Symbol.iterator) === "symbol" ? function (obj) {
    return typeof obj === "undefined" ? "undefined" : _typeof3(obj);
} : function (obj) {
    return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof3(obj);
};

var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
    return typeof obj === "undefined" ? "undefined" : _typeof2(obj);
} : function (obj) {
    return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof2(obj);
};
jQuery(function ($) {
    $('#pagination_b').empty();
    $('#pagination_b').removeData("twbs-pagination");
    $('#pagination_b').unbind('page');
    //分页按钮(
    var onoff = false;
    if ($('#pagination_b').attr('data-total') != 0) {
        var total_page = $('#pagination_b').attr('data-total');
        $('#pagination_b').twbsPagination({
            totalPages: Math.ceil(total_page / 10),
            visiblePages: 5,
            first: "首页",
            last: "末页",
            prev: '上一页',
            next: '下一页',
            onPageClick: function onPageClick(event, page) {
                if (page != 1) {
                    onoff = true;
                }
                if (onoff) {
                    var html = '';
                    var param = {
                        "Comment[]": {
                            "page": page - 1,
                            "count": 10,
                            "Comment": {
                                "holder_id": 1,
                                "type": 2,
                                "Comment": {
                                    "parent_id@": "/id",
                                    "yc_reply_flag": 1
                                }
                            }
                        }
                    };
                    send_ajax('post', '/get', param, function callback(result) {
                        if (result.code == 200) {
                            var data = result['Comment[]'];
                            for (var i = 0; i < data.length; i++) {
                                html += " <div class=\"comment_detail_box\">\n                                        <div class=\"comment_detail\" >\n                                            <img  src=\"http://dpic.tiankong.com/fs/8r/QJ6831113220.jpg?x-oss-process=style/240h\" alt=\"\">\n                                            <div id=\"msg\">\n                                                <p>\n                                                    <span></span>\n                                                    <i> " + data[i].update_time.split('.')[0] + "</i>\n                                                </p>\n                        \n                                                <p class=\"ask\">\n                                                    <span>" + data[i].content + "</span>\n                                                    <img src=\"/asset/image/thum_up2.png\" alt=\"\" class=\"praise_comment\">\n                                                </p>\n                                            </div>\n                                        </div>\n                                        </div>\n                            \n                            ";
                            }
                            $('.comment_box').html(html);
                            ask();
                            answer();
                        }
                    });
                }
            }
        });
    }
    //图片验证码
    changeImgCode();
    function changeImgCode() {
        var img = document.getElementById('text_pic');
        img.src = host + "/api/code/img?phone=" + Math.floor(Math.random() * 100000000000);
    }
    $('#exchange').click(function () {
        changeImgCode();
    });
    var user = JSON.parse(localStorage.getItem('user_info')) || {};
    var user_id = user.id;
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    var create_time = year + '-' + month + '-' + day + '- ' + hour + ':' + minute + ':' + second;
    var update_time = year + '-' + month + '-' + day + '- ' + hour + ':' + minute + ':' + second;
    var holder_id = window.location.href.split('-')[1].split('.')[0];
    var clickParam ={
        holderId:holder_id
    };
    send_ajax('get', '/api/stat/click', clickParam, function callback(result) {   
    });
    //提交评论
    $('#submit').click(function () {
        var content = $('textarea').val();
        var anon_flag = $("input[type='checkbox']").is(':checked');
        var imgCode = $.trim($("#imgCode").val());
        if (anon_flag == false) {
            anon_flag = 0;
        } else {
            anon_flag = 1;
        }
        if (content == "") {
            alert('内容不能为空！');
            return;
        }else if(!imgCode){
            alert('请输入验证码！');
            return;
        }else if(!user_id){
            alert('您还没有登录，请登录后再操作！');
            return;
        }
        var params = {
            "Comment": {
                "user_id": user_id,
                "yc_reply_flag": 0,
                "holder_id": holder_id,
                "type": 2,
                "create_time": create_time,
                "update_time": update_time
            },
            "Tag": "Comment"
        };
        params.Comment.content = content;
        params.Comment.anon_flag = anon_flag;
        send_ajax('post', '/get', params, function callback(result) {
            if (result.code == 200) {
                $('textarea').val('');
                $("#imgCode").val('');
                changeImgCode();
                alert('评论成功');
            }else{
                changeImgCode();
            }
        });
    });
    //文章点赞
    $('#praise_article').click(function () {
        var params = {
            "Like": {
                "type": 1
                // "holder_id": holder_id
            }
        };
        send_ajax('post', '/head', params, function callback(result) {
            if (result.code == 200) {}
        });
    });
    ask();
    function ask() {
        //提问点赞
        $('.praise_comment').click(function () {
            var _this = $(this);
            if ($(this).attr('src') == '/asset/image/thum_up.png') {
                alert('您已经点过赞了！');
                return;
            }
            var ask_id = $(this).parents('.ask').attr('data-id');
            var params = {
                "Like": {
                    "type": 1,
                    "holder_id": ask_id
                }
            };
            send_ajax('post', '/head', params, function callback(result) {
                if (result.code == 200) {
                    $(_this).attr("src", '/asset/image/thum_up.png');
                }
            });
        });
    };
    answer();
    function answer() {
        //回答点赞
        $('.praise_answer').click(function () {
            var _this = $(this);
            if ($(this).attr('src') == '/asset/image/thum_up.png') {
                alert('您已经点过赞了！');
                return;
            }
            //畜牧回复的点赞
            var answer_id = $(this).parents('.answer').attr('data-id');
            var params = {
                "Like": {
                    "type": 1,
                    "holder_id": answer_id
                }
            };
            send_ajax('post', '/head', params, function callback(result) {
                if (result.code == 200) {
                    $(_this).attr("src", '/asset/image/thum_up.png');
                }
            });
        });
    };
    // var clickparams = {
    //     "Article": {
    //         "id": holder_id,
    //         "clicks+": 1
    //     }
    // };
    // send_ajax('post', '/put', clickparams, function callback(res) {
    //     
    // });
    $('#article_btn').click(function () {
        var value = $('#article_search').val();
        if(!value){
            value = $('#article_search').attr('placeholder');
        }
        window.location.href = '/article/article_search.html?keyword=' + value;
    });
    //分享插件
  //分享插件
//   window._bd_share_config = {
//         "common": {
//             "bdSnsKey": {},
//             "bdText": "",
//             "bdMini": "2",
//             "bdMiniList": false,
//             "bdPic": "",
//             "bdStyle": "0",
//             "bdSize": "16"
//         },
//         "share": {}
//     };
// with(document) 0[(getElementsByTagName('head')[0] || body)
//     .appendChild(createElement('script')).src =
//     'https://static.yczihua.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
 });